package com.ezjie.ielts.application;

import java.util.List;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.net.ConnectivityManager;
import cn.sharesdk.framework.authorize.e;

import com.ezjie.baselib.application.MyApplication;
import com.ezjie.ielts.R;
import com.ezjie.ielts.model.CadicatesBean;
import com.ezjie.ielts.model.FilterWordData;
import com.ezjie.ielts.model.ReviewToWordData;
import com.ezjie.ielts.model.ReviewWordData;
import com.ezjie.ielts.model.StudyRecord;
import com.ezjie.ielts.model.WordBean;
import com.ezjie.ielts.model.WordGroupBean;
import com.ezjie.ielts.model.WordStudyStatus;
import com.ezjie.ielts.model.WordStudyingData;
import com.ezjie.ielts.util.BaseConfigure;
import com.ezjie.ielts.util.DownloadUtil;
import com.ezjie.ielts.util.LogUtils;
import com.ezjie.ielts.util.NetworkUtil;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

/**
 * 程序的入口点 可以存储一些短周期的变量
 * 
 * @author renyangyang
 * 
 */
public class YsApplication extends  MyApplication{

	public static YsApplication myApplication;

	private List<CadicatesBean> list;// 筛选的单词组
	private List<Integer> knownList;// 认识的单词 下标列表
	private List<Integer> unknownList;// 不认识的单词 下标列表
	private FilterWordData filterWordData;// 筛选的单词
	private WordStudyingData wordStudyingData;// 正在学习的单词
	private List<StudyRecord> studyRecords;// 当前的学习记录
	private List<WordBean> words;// 学习的单词。
	private WordBean wordBean;// 从第一次学习界面到学习详情传递的对象
	private WordGroupBean mGroupBean;// 复习的单词组
	private WordStudyStatus wordStudyStatus;// 从学习界面 向detail界面传递的对象
	private ReviewWordData reviewWordData;// 从复习滑动界面向做题界面传递的数据
	private ReviewToWordData reviewToWordData;// 从做题界面向释义界面传递的数据
	private static int[] imgs = { R.drawable.review_manager_bg1, R.drawable.review_manager_bg2,
			R.drawable.review_manager_bg3, R.drawable.review_manager_bg4, R.drawable.review_manager_bg5,
			R.drawable.review_manager_bg6, R.drawable.review_manager_bg7, R.drawable.review_manager_bg8,
			R.drawable.review_manager_bg9, R.drawable.review_manager_bg10, R.drawable.review_manager_bg11,
			R.drawable.review_manager_bg12 };

	@Override
	public void onCreate() {
		super.onCreate();
		myApplication = this;

		// 判断是否开启log日志输出
		initLogModel();

		// 初始化单词数据库缓存路径
		DownloadUtil.initCacheDir(getApplicationContext());

		// 设置网络
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkUtil.setNetState(cm, getApplicationContext());
		// 初始化客户端
		BaseConfigure.initClient(getApplicationContext());

		// 异步加载图片初始化
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(myApplication).build();
		ImageLoader.getInstance().init(config);

		// 应用程序入口处调用,避免手机内存过小，杀死后台进程,造成SpeechUtility对象为null
		// 设置你申请的应用appid
		StringBuffer param = new StringBuffer();
		param.append("appid=" + getString(R.string.app_id));
		param.append(",");
		// 设置使用v5+
		param.append(SpeechConstant.ENGINE_MODE + "=" + SpeechConstant.MODE_MSC);
		SpeechUtility.createUtility(YsApplication.this, param.toString());

	}

	/**
	 * 根据是否为debug模式 判断是否开启Log打印
	 */
	private void initLogModel() {
		LogUtils.setDebugable(getApplicationContext());
		// 初始化输出日志级别
		BaseConfigure.setDebug(isApkDebugable(getApplicationContext()));
	}

	/**
	 * 根据是否打包apk获取debug标识, 统一管理日志输出
	 * 
	 * @param context
	 * @return
	 */
	protected boolean isApkDebugable(Context context) {
		try {
			ApplicationInfo info = context.getApplicationInfo();
			return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
		} catch (Exception e) {
			LogUtils.exception(e);
		}
		return false;
	}

	public List<CadicatesBean> getList() {
		return list;
	}

	public void setList(List<CadicatesBean> list) {
		this.list = list;
	}

	public List<Integer> getKnownList() {
		return knownList;
	}

	public void setKnownList(List<Integer> knownList) {
		this.knownList = knownList;
	}

	public List<Integer> getUnknownList() {
		return unknownList;
	}

	public void setUnknownList(List<Integer> unknownList) {
		this.unknownList = unknownList;
	}

	public FilterWordData getFilterWordData() {
		return filterWordData;
	}

	public void setFilterWordData(FilterWordData filterWordData) {
		this.filterWordData = filterWordData;
	}

	public WordStudyingData getWordStudyingData() {
		return wordStudyingData;
	}

	public void setWordStudyingData(WordStudyingData wordStudyingData) {
		this.wordStudyingData = wordStudyingData;
	}

	public List<StudyRecord> getStudyRecords() {
		return studyRecords;
	}

	public void setStudyRecords(List<StudyRecord> studyRecords) {
		this.studyRecords = studyRecords;
	}

	public List<WordBean> getWords() {
		return words;
	}

	public void setWords(List<WordBean> words) {
		this.words = words;
	}

	public WordBean getWordBean() {
		return wordBean;
	}

	public void setWordBean(WordBean wordBean) {
		this.wordBean = wordBean;
	}

	public WordGroupBean getmGroupBean() {
		return mGroupBean;
	}

	public void setmGroupBean(WordGroupBean mGroupBean) {
		this.mGroupBean = mGroupBean;
	}

	public WordStudyStatus getWordStudyStatus() {
		return wordStudyStatus;
	}

	public void setWordStudyStatus(WordStudyStatus wordStudyStatus) {
		this.wordStudyStatus = wordStudyStatus;
	}

	public ReviewWordData getReviewWordData() {
		return reviewWordData;
	}

	public void setReviewWordData(ReviewWordData reviewWordData) {
		this.reviewWordData = reviewWordData;
	}

	public ReviewToWordData getReviewToWordData() {
		return reviewToWordData;
	}

	public void setReviewToWordData(ReviewToWordData reviewToWordData) {
		this.reviewToWordData = reviewToWordData;
	}

	public static int[] getImgs() {
		return imgs;
	}

	public static void setImgs(int[] imgs) {
		YsApplication.imgs = imgs;
	}
}
